
//WebJies JavaScript API for calling web service

var webjies = {
    //Variables
    //color: "red",

    //Functions
    initStorage: function (successEvent) {
        $.ajax({
            type: 'POST',
            url: '/api/jies/init',
            dataType: 'json',
            success: successEvent
        });
    },
    createSamples: function (successEvent) {
        $.ajax({
            type: 'POST',
            url: '/api/jies/samples',
            dataType: 'json',
            success: successEvent
        });
    },

    getJie: function (jieId, successEvent) {
        $.ajax({
            type: 'GET',
            url: '/api/jies/' + jieId,
            dataType: 'json',
            success: successEvent
        });
    },

    search: function (query, successEvent) {
        $.ajax({
            type: 'GET',
            url: '/api/jies',
            dataType: 'json',
            data: { s: query },
            success: successEvent
        });
    },

    insertOrUpdateJie: function (jie, successEvent) {
        $.ajax({
            type: 'POST',
            url: '/api/jies',
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            data: $.toJSON(jie),
            success: successEvent
        });
    },

    deleteJie: function (jieID, successEvent) {
        $.ajax({
            type: 'DELETE',
            url: '/api/jies/' + jieID,
            dataType: 'json',
            success: successEvent
        });
    }
};